<!--
 * @Author: Charlie/彭旺
 * @email: 413157399@qq.com
 * @Date: 2022-07-08 13:45:50
-->
<template>
  <div class="app-container">
      

    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      size="small"
      label-width="150px"
    >
      <div v-for="(item, index) in form" :key="index">

        <el-form-item :label="item.configLabel">
          <el-input v-model="item.value" style="width: 370px" />
        </el-form-item>
      </div>
      <!-- <el-form-item label="文件储存方式">
        <el-radio v-model="form.store_brokerage_statu" :label="1">本地储存</el-radio>
        <el-radio v-model="form.store_brokerage_statu" :label="2">云储存</el-radio>
      </el-form-item> -->
      <!-- <el-form-item label="包邮金额">
        <el-input v-model="form.user_extract_min_price" style="width: 370px;" />
        <p style="color: red">如果设置满包邮0 表示全局包邮，如果设置大于0表示满这价格包邮，否则走运费模板算法</p>
      </el-form-item>
     -->
      <!-- <el-form-item label="隐藏充值按钮">
        <el-radio v-model="form.store_brokerage_open" :label="1">显示</el-radio>
        <el-radio v-model="form.store_brokerage_open" :label="2">隐藏</el-radio>
      </el-form-item> -->
      <el-form-item label="">
        <el-button type="primary" @click="doSubmit">保存修改</el-button>
         <!-- <el-button type="primary" @click="open">新增</el-button>
         <el-button type="primary" @click="del">删除</el-button> -->
            <Dialog ref="add"/>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  del,
  add,
  get,
  getQuery,
  getQuerybyid,
  updateconfig,
} from "@/api/yxSystemConfig";
import Dialog from './component/dialog.vue';
export default {
  components: { Dialog },
  data() {
    return {
      delLoading: false,
      newarr: [],
      form: {},
      rules: {},
    };
  },
  mounted() {
    console.log(getQuery, 9999999);
    this.getQuerys();

    // http://47.108.251.120:8100/config/queryById?id=1
  },
  methods: {
      open() {
        console.log( this.$refs.add.opendialog);
        // this.$refs.add._directInactive=true
        this.$refs.add.opendialog()
      },
    getQuerybyids() {
      getQuerybyid({ id: "1" })
        .then((res) => {
          console.log(res, 999999);
        })
        .catch((err) => {
          console.log(err.response.data.message);
        });
    },
    getQuerys() {
      getQuery()
        .then((res) => {
          console.log(res.data.content, 888888888);
          this.form = res.data.content;
          console.log(this.form);
        })
        .catch((err) => {
          console.log(err.response.data.message);
        });
    },

    doSubmit() {
      this.newarr = this.form.map(({ configName, value }) => ({
        configName,
        value,
      }));
      console.log("newarr", this.newarr);
      this.$nextTick(() => {
        updateconfig(this.newarr)
          .then((res) => {
            console.log(res, "updata");
            this.$message({
          message: '恭喜你，修改成功',
          type: 'success'
        });
          })
          .catch((err) => {
             this.$message.error('错了哦，这是一条错误消息');
            console.log(err.response.data.message);
          });
      });
    },
  },
};
</script>
<style scoped>
</style>
